package com.usvisatrack.core.common;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.usvisatrack.core.common.search.InternalSearch;
import com.usvisatrack.core.dao.model.EntityListener;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.hibernate.criterion.Restrictions;
import org.hibernate.search.annotations.DateBridge;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Resolution;
import org.hibernate.search.annotations.Store;

public class InternalSearchFactory {
	/**
	 * Gets a list of all internal searches.
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static List<InternalSearch> getAll() {
		return Factory.createCriteria(InternalSearch.class).list();
	}

	/**
	 * Gets an internal search by the specified id.
	 * 
	 * @param id
	 * @return
	 */
	public static InternalSearch get(int id) {
		return Factory.get(InternalSearch.class, id);
	}

	/**
	 * Saves the specified internal search.
	 * 
	 * @param search
	 */
	public static void save(InternalSearch search) {
		Factory.save(search);
	}

	/**
	 * Deletes the specified internal search.
	 * 
	 * @param search
	 */
	public static void delete(InternalSearch search) {
		Factory.delete(search);
	}

	/**
	 * Gets a list of searches available to the specified user.
	 * 
	 * @param user
	 * @return
	 */
	@SuppressWarnings("unchecked")
	/**
	 * Gets an internal search by name.
	 * @param name
	 * @return
	 */
	public static InternalSearch get(String name) {
		return (InternalSearch) Factory.createCriteria(InternalSearch.class).add(Restrictions.eq("name", name)).setMaxResults(1)
				.uniqueResult();
	}

}
